package com.jkm.controller;

import com.jkm.model.User;
import com.jkm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/insert")
    @ResponseBody
    public void insert(){
        User user = new User();
        user.setAge(1001);
        user.setName("kk");
        try {
            userService.save(user);
        }catch (Exception e){
            e.getMessage();
        }
    }

    @RequestMapping("/selectById/{id}")
    @ResponseBody
    public User insert(@PathVariable Integer id){
        User user = userService.selectById(id);
        return user;
    }

}
